import { IncomingMessage, Server, ServerResponse } from "http";
const http = require('http');
let dateformat = require('dateformat');
const app: Server = http.createServer();
require('./model/index');
const path = require('path');
const router = require('./route/index');

const serveStatic = require('serve-static');
const serve = serveStatic(path.join(__dirname, 'public'));

const template = require('art-template');
template.defaults.root = path.join(__dirname, 'view');
template.defaults.extname = '.art';
template.defaults.imports.dateformat = dateformat;

app.on('request', (req: IncomingMessage, res: ServerResponse) => {
  // console.log('请求来了', req);
  router(req, res, () => {
    console.log('router start...');
  });
  serve(req, res, () => {
    console.log('staticServer start...');
  });
});

app.listen(3002, () => {
  console.log('宠物服务器创建成功！端口号3002');
});